package com.bbs.service.impl;

import com.bbs.domain.Word;
import com.bbs.entity.PageResult;
import com.bbs.mapper.WordMapper;
import com.bbs.service.WordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName WordServiceImpl
 * @Description TODO
 * @Author chen hong wei
 * @Date 2019/9/21 14:43
 */

@Service
public class WordServiceImpl implements WordService {

    @Autowired
    private WordMapper wordMapper;

    /**
    * @author chen hong wei
    * @Description 查询所有 展示
    * @Date 15:55 2019/9/21
    * @Param []
    * @return java.util.List<com.bbs.domain.Word>
    **/
    @Override
    public List<Word> findList() {
        List<Word> words = wordMapper.selectAll();
//        System.out.println(words);
        return words;
    }

    /**
    * @author chen hong wei
    * @Description 分页   查询敏感词
    * @Date 16:03 2019/9/21
    * @Param [page, size] 页数   条数
    * @return java.util.List<com.bbs.domain.Word>
    **/
    @Override
    public PageResult<Word> findPage(int page, int size ){
        PageHelper.startPage(page,size);
        Page<Word> words = (Page<Word>) wordMapper.selectAll();
//        System.out.println(words.getPageNum());//d当前页
//        System.out.println(words.getPages());//中共
        return new PageResult<Word>(words.getTotal(),words.getPageNum(),words.getPages(),words.getResult());

    }

    /**
    * @author chen hong wei
    * @Description  删除 敏感 词
    * @Date 22:12 2019/9/21
    * @Param [id]
    * @return void
    **/
    @Override
    public void delete(int id) {
        if(id<=0){
            throw new RuntimeException("参数异常");
        }
       wordMapper.deleteByPrimaryKey(id);
    }


    /**
    * @author chen hong wei
    * @Description 新增
    * @Date 22:19 2019/9/21
    * @Param [word]
    * @return void
    **/
    @Override
    public void insert(Word word) {
        System.out.println(word.getStatus());
        wordMapper.insertSelective(word);
    }
    
    /**
    * @author chen hong wei
    * @Description 修改 
    * @Date 23:23 2019/9/21
    * @Param [wordid, status]
    * @return void
    **/
    @Override
    public void update(Integer wordid, int status) {
        Word word = new Word();
        word.setWordid(wordid);
        word.setStatus(status);
        wordMapper.updateByPrimaryKeySelective(word);
    }


}